package com.company.project.web;
import com.company.project.core.Result;
import com.company.project.core.ResultGenerator;
import com.company.project.model.JdPhones;
import com.company.project.model.JdRegions;
import com.company.project.service.JdRegionsService;
import com.company.project.util.StringUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by CodeGenerator on 2019/07/25.
 */
@RestController
@RequestMapping("/jd/regions")
public class JdRegionsController {
	@Resource
	private JdRegionsService jdRegionsService;

	@GetMapping("/list")
	public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {

		try {
			BufferedReader reader = new BufferedReader(new FileReader("/Users/72cy-0101-01-0009/Downloads/regions.csv"));//换成你的文件名
			reader.readLine();//第一行信息，为标题信息，不用,如果需要，注释掉
			String line = null;

			int i = 0;

			while((line=reader.readLine())!=null){

				System.out.println("line --- " + line);

				String item[] = line.split(",");//
				String id = item[0];
				String province = item[1];
				String city = item[2];
				String zipCode = item[3];
				String areaCode = item[4];

				JdRegions jdRegions = new JdRegions();
				jdRegions.setId(StringUtil.getUUID());
				jdRegions.setAreaCode(areaCode);
				jdRegions.setCity(city);
				jdRegions.setProvince(province);
				jdRegions.setZipCode(zipCode);
				jdRegions.setRegId(Integer.valueOf(id));

				jdRegionsService.save(jdRegions);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return ResultGenerator.genSuccessResult("");
	}
}
